import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test01 {

    public static String[] chaifen(String str,String fengefu){
        List<String> list = new ArrayList<>();
        int start = 0;
        int length = fengefu.length();
        for (int i = 0; i <= str.length() - length; i++) {
            if(str.substring(i,i + length).equals(fengefu)) {
                list.add(str.substring(start, i));
                start = i + length;
                i += length - 1;
            }
        }
        list.add(str.substring(start));
        return list.toArray(new String[0]);
    }

    public static String hebing(String[] str,String fengefu){
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < str.length; i++) {
            result.append(str[i]);
            if(i < str.length - 1){
                //添加分隔符
                result.append(fengefu);
            }
        }
        return result.toString();
    }

    public static void main(String[] args) {
        String str = "ab&&2";
        String fengefu = "&&";
        String s = Arrays.toString(chaifen(str, fengefu));
        System.out.println(s);


//        String[] str = new String[]{"ab","2"};
//        String fengefu = "&&";
//        System.out.println(hebing(str, fengefu));
    }
}
